﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DNADataHiding.Model.Encryption
{
    class EncryptionUtils
    {
        public static string GetBinaryMessage(string message)
        {
            string retValue = string.Empty;

            byte[] bytes = ASCIIEncoding.ASCII.GetBytes(message);

            foreach (byte b in bytes)
            {
                retValue += Convert.ToString(b, 2).PadLeft(8, '0'); ;
            }

            return retValue;
        }

        public static string GetMessageFromBinary(string binaryMessage)
        {
            int numOfBytes = binaryMessage.Length / 8;
            byte[] bytes = new byte[numOfBytes];
            for (int i = 0; i < numOfBytes; ++i)
            {
                bytes[i] = Convert.ToByte(binaryMessage.Substring(8 * i, 8), 2);
            }

            return ASCIIEncoding.ASCII.GetString(bytes);
        }
    }
}
